<?php
    include('./library/conn.php');
    $username=$_REQUEST['uname'];
    $password = $_REQUEST['userpw'];
    $email = $_REQUEST['useremail'];
    $phone = $_REQUEST['usertel'];
    $country = $_REQUEST['cuntry'];
    $year = $_REQUEST['year'];
    $month = $_REQUEST['month'];
    $day = $_REQUEST['day'];
    if($email){
        $select="select * from users where email='$email'";
        $phone='0';
    }else{
        $select="select * from users where phone='$phone'";
        $email ='null';
    }
    $result=$mysqli->query($select);
    if($result->num_rows>0){
        echo '<script>alert("用户已存在,请勿重复注册！");</script>';
        echo '<script>location.href="./reg.html";</script>';
        $mysqli->close();  //关闭数据库连接
        die();//终止代码
    }
    $insert = "insert into users (username,password,country,email,year,month,day,phone) values ('$username','$password','$country','$email','$year','$month','$day','$phone')";
    $res = $mysqli->query($insert);
    $mysqli->close();
    if($res){
        echo '<script>alert("用户注册成功,即将进入登录页面！");</script>';
        echo '<script>location.href="./login.html"</script>';
    }
?>